<?php
/*
 * Copyright notice
 * 
 * (c) 2009 MH-Dev.de, Martin Hesse <info@mh-dev.de>
 * 
 * This script is part of the MH-Dev.-Board project. The MH-Dev.-Board 
 * is free software; you can redistribute it and/or modify it under the 
 * terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, 
 * or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty 
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU 
 * General Public License along with this program; if not, 
 * see http://www.gnu.org/licenses/.
 */


/**
 * Board overview
 *
 * @author	Martin Hesse <info@mh-dev.de>
 * @package	MH-Dev.-Board
 */
class IndexController extends Zend_Controller_Action
{
	private $registry; // registry
	private $auth; // user-values
	private $settings; // board-settings
	
	public function init()
	{		
		// registry
		$this->registry = Zend_Registry::getInstance();
		
		// settings
		$this->settings	= $this->registry->get('settings');
		
		// auth
		$auth = Zend_Auth::getInstance();
		$this->view->auth = $auth->hasIdentity();
    	
		if($auth->hasIdentity())
		{
			$this->view->auth_role 			= $auth->getIdentity()->role;
			$this->view->username 			= $auth->getIdentity()->username;
			$this->view->auth_uid			= $auth->getIdentity()->uid;
			$this->view->unread_messages	= $auth->getIdentity()->count_unread_messages;
		}
		else
		{
			$this->view->username 	= $this->registry->get('lang')->_('guest');
		}

		$this->auth = $auth;
    	
		// lang
		$this->view->translate 		= $this->registry->get('lang');
		
		// flash messenger
		$this->view->flashMessenger	= $this->_helper->FlashMessenger;
		
		// include jquery
		$baseurl = new MHDEV_View_Helper_BaseUrl();
		$this->view->headScript()->appendFile($baseurl->BaseUrl() . '/static/css/default/jquery.css');
		$this->view->headScript()->appendFile($baseurl->BaseUrl() . '/static/js/jquery-1.3.2.min.js');
		$this->view->headScript()->appendFile($baseurl->BaseUrl() . '/static/js/jquery-ui-1.7.2.custom.min.js');
		$this->view->headScript()->appendFile($baseurl->BaseUrl() . '/static/js/jquery.cookie.js');
		$this->view->headScript()->appendFile($baseurl->BaseUrl() . '/static/js/frontend.js');
	}
	
	
	
	/*
	 * Displays the categories and boards
	 * 
	 * @param null
	 * 
	 * @return Zend_View
	 */
	public function indexAction()
	{			
		// database
		$categories = new Categories();
		$boards 	= new Boards();

		// fetch
		$fetch_categories	= $categories->fetchAll(null, 'sort_uid ASC');
		
		// view
		$this->view->result_count 	= $fetch_categories->count();
		$this->view->result			= $fetch_categories->toArray();
		$this->view->boards			= $boards;
		$this->view->settings		= $this->settings;
	}
}